/* 
 * Copyright (C), 2016-2020, 厦门盈欣宝金融信息服务有限公司
 * Project Name :boot-parent
 * File Name: org.easytouseit.rabbitmq.config
 * Encoding UTF-8 
 * Version: 1.0 
 * Date: 2018-09-14 16:19
 * History:  
 * 1. Date: 2018-09-14
 *    Author: guojm 
 *    Modification: 新建
 * 2. ...
 */
package org.easytouseit.rabbitmq.topic.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.support.RetryTemplate;

/**
 * @author guojm
 * @version V1.0
 * @date 2018-09-14 下午 16:19
 */
@Configuration
public class TopicRabbitMQConfig {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Value("${spring.rabbitmq.host}")
    private String host;

    @Value("${spring.rabbitmq.port}")
    private int port;

    @Value("${spring.rabbitmq.username}")
    private String username;

    @Value("${spring.rabbitmq.password}")
    private String password;

    @Value("${spring.rabbitmq.virtual-host}")
    private String virtualHost;

    @Value("${spring.rabbitmq.publisher-confirms}")
    private boolean publisherConfirms;


    public final static String TOPIC_QUEUE_ONE = "topic.queue.one";
    public final static String TOPIC_QUEUE_TWO = "topic.queue.two";
    public final static String TOPIC_EXCHANGE_NAME = "topic-exchange";
    public final static String TOPIC_ROUTING_ONE = "topic.queue.one";
    public final static String TOPIC_ROUTING_TWO = "topic.queue";
    @Bean("topicQueueOne")
    public Queue topicQueueOne() {
        return QueueBuilder.durable(TOPIC_QUEUE_ONE).build();
    }
    @Bean("topicQueueTwo")
    public Queue topicQueueTwo() {
        return QueueBuilder.durable(TOPIC_QUEUE_TWO).build();
    }

    @Bean("exchangeTopic")
    public TopicExchange exchangeTopic() {
        return new TopicExchange(TOPIC_EXCHANGE_NAME,true,false);
    }

    @Bean
    public Binding bindingTopicQueueOne(@Qualifier("topicQueueOne") Queue topicQueueOne,
                                        @Qualifier("exchangeTopic") TopicExchange exchangeTopic) {
        return BindingBuilder.bind(topicQueueOne).to(exchangeTopic).with("topic.queue.one");
    }
    @Bean
    public Binding bindingTopicQueueTwo(@Qualifier("topicQueueTwo") Queue topicQueueTwo,
                                        @Qualifier("exchangeTopic") TopicExchange exchangeTopic) {
        return BindingBuilder.bind(topicQueueTwo).to(exchangeTopic).with("topic.queue.#");
    }

}
